local skel = fk.CreateSkill {
  name = "emo__fanjifb",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__fanjifb"] = "反击风暴",
  [":emo__fanjifb"] = "你可以将装备牌当<a href=':borrow_arrows'>【草船借箭】</a>使用，以此法获得的牌不计入次数限制与手牌上限。",

  ["#emo__fanjifb-ask"] = "反击风暴:将1张装备牌当【草船借箭】使用",
  ["@@emo__fanjifb-inhand"] = "反击",

  ["$emo__fanjifb1"] = "没想到吧，我又回来啦",
  ["$emo__fanjifb2"] = "严阵以待",
}

skel:addEffect("viewas", {
  anim_type = "defensive",
  pattern = "borrow_arrows",
  prompt = "#emo__fanjifb-ask",
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("borrow_arrows")
    c.skillName = skel.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function (self, player, response)
    return not response
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.to == player and move.skillName == "borrow_arrows_skill" and move.toArea == Card.PlayerHand then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(player.player_cards[Player.Hand], info.cardId) then
            player.room:setCardMark(Fk:getCardById(info.cardId), "@@emo__fanjifb-inhand", 1)
          end
        end
      end
    end
  end,
})

skel:addEffect(fk.PreCardUse, {
  can_refresh = function (self, event, target, player, data)
    return data.card:getMark("@@emo__fanjifb-inhand") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
  end,
})

skel:addEffect("maxcards", {
  exclude_from = function (self, player, card)
    return card:getMark("@@emo__fanjifb-inhand") ~= 0
  end,
})

skel:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card, to)
    return card and card:getMark("@@emo__fanjifb-inhand") ~= 0
  end,
})

return skel
